/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var now = new Date();
var thisMonth = now.format('m');
var thisYear = now.format('Y');

var fieldLabel2 = new Array('综合电压合格率', 'A类', 'B类', 'C类', 'D类', 'D类城市居民端', 'D类农村居民端', '测点数合计');
var fieldLabel1 = new Array('本月', '本年累计', '本月', '本年累计', '本月', '本年累计', '本月', '本年累计', '本月', '本年累计', '本月', '本年累计');
var fieldLabel = new Array('单位名称', '本月(%)', '本年累计(%)', '年度指标',
        '合格率(%)', '测点数', '合格率(%)', '平均测点数',
        '合格率(%)', '测点数', '合格率(%)', '平均测点数',
        '合格率(%)', '测点数', '合格率(%)', '平均测点数',
        '合格率(%)', '测点数', '合格率(%)', '平均测点数',
        '合格率(%)', '测点数', '合格率(%)', '平均测点数',
        '合格率(%)', '测点数', '合格率(%)', '平均测点数',
        '本月测点数', '平均测点数');
var fieldName = new Array("orgName", "rateTotal", "avgRateTotal", "planRate",
        "rateA", "A", "avgRateA", "avgA",
        "rateB", "B", "avgRateB", "avgB",
        "rateC", "C", "avgRateC", "avgC",
        "rateD", "D", "avgRateD", "avgD",
        "rateDC", "DC", "avgRateDC", "avgDC",
        "rateDN", "DN", "avgRateDN", "avgDN"
        , "ABCD", "avgABCD", 'dateStr');
var _pageSize = 20;


var store = new Ext.data.JsonStore({    
    url: "../../../servlet/data/YsjLoad",
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: fieldName,
    autoLoad: true,
    baseParams:{lock:lock,cmd:loadCmd,reportStatus:reportStatus,yearTo:thisYear,start:0,limit:99999}
});



var centercolumnModel = new Ext.grid.ColumnModel({
    columns: [
        {header: '月份', width: 100, dataIndex: 'dateStr', align: 'center'},
        {header: fieldLabel[0], width: 100, dataIndex: fieldName[0], align: 'center'},
        {header: fieldLabel[1], width: 100, dataIndex: fieldName[1], align: 'center'},
        {header: fieldLabel[2], width: 100, dataIndex: fieldName[2], align: 'center'},
        {header: fieldLabel[3], width: 100, dataIndex: fieldName[3], align: 'center'},
        {header: fieldLabel[4], width: 100, dataIndex: fieldName[4], align: 'center',xtype:'numbercolumn',format:'0.000'},
        {header: fieldLabel[5], width: 100, dataIndex: fieldName[5], align: 'center'},
        {header: fieldLabel[6], width: 100, dataIndex: fieldName[6], align: 'center'},
        {header: fieldLabel[7], width: 100, dataIndex: fieldName[7], align: 'center'},
        {header: fieldLabel[8], width: 100, dataIndex: fieldName[8], align: 'center'},
        {header: fieldLabel[9], width: 100, dataIndex: fieldName[9], align: 'center'},
        {header: fieldLabel[10], width: 100, dataIndex: fieldName[10], align: 'center'},
        {header: fieldLabel[11], width: 100, dataIndex: fieldName[11], align: 'center'},
        {header: fieldLabel[12], width: 100, dataIndex: fieldName[12], align: 'center'},
        {header: fieldLabel[13], width: 100, dataIndex: fieldName[13], align: 'center'},
        {header: fieldLabel[14], width: 100, dataIndex: fieldName[14], align: 'center'},
        {header: fieldLabel[15], width: 100, dataIndex: fieldName[15], align: 'center'},
        {header: fieldLabel[16], width: 100, dataIndex: fieldName[16], align: 'center'},
        {header: fieldLabel[17], width: 100, dataIndex: fieldName[17], align: 'center'},
        {header: fieldLabel[18], width: 100, dataIndex: fieldName[18], align: 'center'},
        {header: fieldLabel[19], width: 100, dataIndex: fieldName[19], align: 'center'},
        {header: fieldLabel[20], width: 100, dataIndex: fieldName[20], align: 'center'},
        {header: fieldLabel[21], width: 100, dataIndex: fieldName[21], align: 'center'},
        {header: fieldLabel[22], width: 100, dataIndex: fieldName[22], align: 'center'},
        {header: fieldLabel[23], width: 100, dataIndex: fieldName[23], align: 'center'},
        {header: fieldLabel[24], width: 100, dataIndex: fieldName[24], align: 'center'},
        {header: fieldLabel[25], width: 100, dataIndex: fieldName[25], align: 'center'},
        {header: fieldLabel[26], width: 100, dataIndex: fieldName[26], align: 'center'},
        {header: fieldLabel[27], width: 100, dataIndex: fieldName[27], align: 'center'},
        {header: fieldLabel[28], width: 100, dataIndex: fieldName[28], align: 'center'},
        {header: fieldLabel[29], width: 100, dataIndex: fieldName[29], align: 'center'}
    ],
    defaultSortable: true,
    rows: [
        [
            {width: 100, rowspan: 2},
            {width: 100, rowspan: 2},
            {width: 100, header: fieldLabel2[0], colspan: 3, align: 'center', rowspan: 1},
            {width: 100, header: fieldLabel2[1], colspan: 4, align: 'center', rowspan: 1},
            {width: 100, header: fieldLabel2[2], colspan: 4, align: 'center', rowspan: 1},
            {width: 100, header: fieldLabel2[3], colspan: 4, align: 'center', rowspan: 1},
            {width: 100, header: fieldLabel2[4], colspan: 4, align: 'center', rowspan: 1},
            {width: 100, header: fieldLabel2[5], colspan: 4, align: 'center', rowspan: 1},
            {width: 100, header: fieldLabel2[6], colspan: 4, align: 'center', rowspan: 1},
            {width: 100, header: fieldLabel2[7], colspan: 2, align: 'center', rowspan: 1}
        ], [
            {width: 100, rowspan: 1},
            {width: 100, rowspan: 1},
            {width: 100, rowspan: 1},
            {width: 100, header: fieldLabel1[0], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[1], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[2], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[3], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[4], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[5], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[6], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[7], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[8], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[9], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[8], colspan: 2, align: 'center'},
            {width: 100, header: fieldLabel1[9], colspan: 2, align: 'center'},
            {width: 100, rowspan: 1},
            {width: 100, rowspan: 1}
        ]
    ]
});


var centergrid = new Ext.grid.GridPanel({
    title: currentOrgName+' 综合电压合格率月报表',
    store: store,
    colModel: centercolumnModel,
    enableColumnMove: false,
    viewConfig: {
        forceFit: false
    },
    plugins: [new Ext.ux.plugins.GroupHeaderGrid()],
    loadMask: true,
    tbar: new Ext.Toolbar([
        reportCombo,
        rangeCombo,
        '-',
        yearToCombo,        
        lblYear,
        '-',        
        searchButton,
        '-',
        {
            xtype: 'button',
            text: '导出',
            iconCls: 'icon-excel',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: downloadExcel
        }
    ]),
    bbar: new Ext.PagingToolbar({
        pageSize: _pageSize,
        store: store,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg: '目前没有信息'
    })
});

store.load({
    params: {
        start: 0,
        limit: _pageSize
    }
});

function downloadExcel() {
    store.baseParams.type=100;
    var encodeParams = Ext.urlEncode(store.baseParams);
    open('../../../servlet/common/ExcelFileCreate?' + encodeParams);
}

function buildWindow() {
    var applicationUI = new Ext.Viewport({
        layout: 'fit',
        items: [
            centergrid
        ]
    });
    if(reportStatus ===1){
        //Ext.getCmp('ReportStatus').setVisible(false);
        Ext.getCmp('ReportStatus').setValue(1);
    }
}
Ext.onReady(buildWindow);



